package com.qinglei.recoup.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qinglei.recoup.common.domain.CommonRes;

import com.qinglei.recoup.system.domain.*;
import com.qinglei.recoup.system.pojo.HealthDetailParam;
import com.qinglei.recoup.system.pojo.HealthDetailParamV1;
import com.qinglei.recoup.system.pojo.PageVO;
import com.qinglei.recoup.system.pojo.RadarWechatParam;
import com.qinglei.recoup.system.service.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author dqh
 */
@RestController
@RequestMapping("/radar-wechat")
public class RadarWechatController {

    @Autowired
    private RadarWechatService  radarWechatService;

    @Autowired
    private BedHealthDailyStatisticsService bedHealthDailyStatisticsService;

    @Autowired
    private BedService bedService;

    @Autowired
    private RadarService radarService;

    /**
     * 新增绑定雷达
     * @param radarWechat
     * @return
     */
    @PostMapping("/add")
    public CommonRes<RadarWechat> add(@Valid @RequestBody RadarWechat radarWechat){
        return   radarWechatService.add(radarWechat);
    }

    /**
     * 解除绑定雷达
     * @param radarWechatId
     * @return
     */
    @DeleteMapping("/remove")
    public CommonRes remove(Long radarWechatId,String snCode){
       return radarWechatService.remove(radarWechatId,snCode);
    }


    /**
     * 获取当前微信openId下所有绑定的设备
     * @param radarWechatParam
     * @return
     */
    @GetMapping("/list")
    public CommonRes<PageVO<RadarWechat>> list(@Valid RadarWechatParam radarWechatParam){
         return radarWechatService.listForOpenId(radarWechatParam);
    }

    /**
     * 订阅，解除订阅雷达设备
     * @param openId
     * @return
     */
    @PostMapping("/subscribe")
    public CommonRes subscribe(String openId,String snCode,Integer isSubscribe){
        return radarWechatService.subscribe(openId,snCode,isSubscribe);
    }

    /**
     * 新增或修改昵称
     * @param
     * @return
     */
    @PostMapping("/addOrUpdatelabel")
    public CommonRes addOrUpdatelabel(@Valid @RequestBody RadarWechat radarWechat){
        return radarWechatService.addOrUpdatelabel(radarWechat);
    }

    /**
     * 获取健康报告列表
     * @param
     * @return
     */
    @GetMapping("/healthReportList")
    public CommonRes healthReportList(String snCode,String openId){
        return radarWechatService.healthReportList(snCode,openId);
    }

    @GetMapping("/getBedIdBySnCode")
    public CommonRes<Bed> getBedIdBySnCode(String snCode) {
        Bed bed = bedService.getBedBySn(snCode);
        return CommonRes.ok(bed).setMsg("查询成功");
    }

    @GetMapping("/getHealthReport")
    public CommonRes<BedHealthBreathDailyData> getHealthReport(@Valid HealthDetailParamV1 param) {
        BedHealthBreathDailyData healthReport = bedHealthDailyStatisticsService.getHealthReport(param);
        return CommonRes.ok(healthReport);
    }

    @GetMapping("/IsBindingOpenId")
    public CommonRes getRadarBySnCode(String snCode,String openId) {

        return  radarWechatService.IsBindingOpenId(snCode,openId);
    }

}
